home *** CD-ROM | disk | FTP | other *** search
- /*
- * PaintDisplay.c
- *
- * This program supplies the code needed for the PostCard application
- * to generate a stand alone Paint file.
- *
- * copyright 1987, Joel McNamara - All Rights Reserved
- * for MacTutor Magazine
- *
- * initial coding - October 12, 1987
- *
- */
-
- #include <MacTypes.h>
- #include <QuickDraw.h>
- #include <WindowMgr.h>
- #include <EventMgr.h>
- #include <MemoryMgr.h>
- #include <SegmentLdr.h>
-
- /* setup the world, display the image, and wait for a click */
- main()
- {
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- FlushEvents(everyEvent,0);
-
- displayPaint();
- while (!Button());
- }
-
-
- /* the guts of the paint display program */
- displayPaint()
- {
- char *srcPtr, *dstPtr, *saveDstPtr, *skipPtr;
- int srcFile, scanLine, vRef, temp;
- long srcSize, paintSize;
- Str255 thisProgram;
- StringPtr thisVolume;
- GrafPort aPort;
- BitMap theBitMap;
- Rect myRect;
- WindowPtr myWind;
- Handle thisHandle;
-
- /* we'll be sloppy with the nonrelocatable pointers and let them
- all get cleaned up upon exiting */
-
- /* the first 512 header bytes to skip */
- srcSize = 512;
- skipPtr = NewPtr(512);
- if (srcPtr == 0L)
- ErrorRoutine(FALSE,0);
-
- /* the biggest it can be */
- srcPtr = NewPtr(51840);
- if (srcPtr == 0L)
- ErrorRoutine(FALSE,0);
-
- /* see who and where we are... */
- if (GetVol(&thisVolume,&vRef) != noErr)
- ErrorRoutine(FALSE,0);
-
- GetAppParms(&thisProgram,&temp,&thisHandle);
-
- /* then open our data fork and read past the header */
- if (FSOpen(thisProgram,vRef,&srcFile) != noErr)
- ErrorRoutine(TRUE,srcFile);
-
- if (FSRead(srcFile,&srcSize,skipPtr) != noErr)
- ErrorRoutine(TRUE,srcFile);
-
- /* see how big we really are... */
- if (GetEOF(srcFile,&paintSize) != noErr)
- ErrorRoutine(TRUE,srcFile);
-
- paintSize -= 512;
-
- /* now read the rest of the bytes and close */
- if (FSRead(srcFile,&paintSize,srcPtr) != noErr)
- ErrorRoutine(TRUE,srcFile);
-
- if (FSClose(srcFile) != noErr)
- ErrorRoutine(TRUE,srcFile);
-
- /* get a destination pointer... */
- dstPtr = NewPtr(51840);
- if (dstPtr == 0L)
- ErrorRoutine(FALSE,0);
-
- saveDstPtr = dstPtr;
- scanLine = 1;
-
- /* and start unpacking the compressed Paint data */
- for (scanLine = 1; scanLine <= 720; scanLine++)
- UnpackBits(&srcPtr,&dstPtr,72);
-
- /* make a window */
- SetRect(&myRect,12,35,500,325);
- myWind = NewWindow(0L,&myRect,"\p",TRUE,1,-1L,FALSE,99);
-
- /* configure our bitmap */
- theBitMap.baseAddr = saveDstPtr;
- theBitMap.rowBytes = 72;
-
- theBitMap.bounds.top = 0;
- theBitMap.bounds.left = 0;
- theBitMap.bounds.bottom = 72 * 8;
- theBitMap.bounds.right = 720;
-
- /* and copy the Paint bits into our window */
- CopyBits(&theBitMap, &myWind->portBits, &myWind->portRect,
- &myWind->portRect, srcCopy, 0L);
- }
-
-
- /* simple no frills, beep and quit */
- ErrorRoutine( closeFile, fileNum )
- Boolean closeFile;
- int fileNum;
- {
- SysBeep(5);
- if (closeFile)
- FSClose(fileNum);
- ExitToShell();
- }
-